import JSEncrypt from "jsencrypt/bin/jsencrypt.min";

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey = `-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgXG04cRq/BGjI3abUyu9
jZKjhC4VOTrlqbNwF/jYiBvKWpc34ng7YDozMBbb33abLP5Vwgvmlg9GNPuiDILM
Iy4x0V2PmGMcOYqh15GCu48JISCUD7chTHSC6sI8tQdkZ1paxVjx30UvJ5dyj1DK
Vl8W928C85ENRn8jXckdAgd8fAkKIPtOhG0qqKNtSL7N5BfjucWk4xAKiqEC3hVH
9zHj5ibZtoLVHLf+3S8xCkYhMmvVcyR1HTHmEcaPHO7oNytWNaIlaf25VdNj0AEx
7UM58fqULF88xiK1waWh7JXsukEUq0DCjzfNpbMfHf+b03PxPAr8XRECag6iN8wi
OQIDAQAB
-----END PUBLIC KEY-----`;

const privateKey = `-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEAgXG04cRq/BGjI3abUyu9jZKjhC4VOTrlqbNwF/jYiBvKWpc3
4ng7YDozMBbb33abLP5Vwgvmlg9GNPuiDILMIy4x0V2PmGMcOYqh15GCu48JISCU
D7chTHSC6sI8tQdkZ1paxVjx30UvJ5dyj1DKVl8W928C85ENRn8jXckdAgd8fAkK
IPtOhG0qqKNtSL7N5BfjucWk4xAKiqEC3hVH9zHj5ibZtoLVHLf+3S8xCkYhMmvV
cyR1HTHmEcaPHO7oNytWNaIlaf25VdNj0AEx7UM58fqULF88xiK1waWh7JXsukEU
q0DCjzfNpbMfHf+b03PxPAr8XRECag6iN8wiOQIDAQABAoIBAD6QMiBCmoDdl29v
BpCy3el8u/qJeWmRTWpxl1aGyEU0xV92oiSb/vq59n6iNcAyZ7rd7J4euWLC3CiE
jKSmXTsNuzdZlKtPD9fB6QozQrAbaIqx384esYHt+E619bh7a6xGcAPdQv4qRqnI
ma6qGjmXuRZ7eb42V+fAUFwmdZZCSOLYt6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function encrypt(txt) {
  const encryptor = new JSEncrypt();
  encryptor.setPublicKey(publicKey); // 设置公钥
  return encryptor.encrypt(txt); // 对数据进行加密
}

// 解密
export function decrypt(txt) {
  const encryptor = new JSEncrypt();
  encryptor.setPrivateKey(privateKey); // 设置私钥
  return encryptor.decrypt(txt); // 对数据进行解密
}
